package com.marco.ipdata.domain;

import java.io.Serializable;
import java.util.Map;

/**
 * StaticIPDTO.java
 * Create on 2017/5/5
 * Copyright(c) JD Inc 2017. All Rights Reserved.
 * <pre>
 * 功能说明：统计新版IP的各项指标
 * </pre>
 */
public class StaticIPDTO implements Serializable {
    //总的IP数量
    private Long totalQty;
    //中国IP数量
    private Long chinaQty;
    //省级精度数量
    private Long proLvQty;
    //市级精度数量
    private Long cityLvQty;
    //区级精度数量
    private Long disLvQty;
    //未知精度数量
    private Long unknownQty;
    //未知运营商数量
    private Long unknownIspQty;
    //原始数据0
    private Long orignQty;
    //API数据1
    private Long apiQty;
    //IPIP数据2
    private Long ipipQty;

    //运营商分布
    private Map<String, Integer> ispDistribution;

    public StaticIPDTO(Builder builder) {
        this.totalQty = builder.totalQty;
        this.chinaQty = builder.chinaQty;
        this.proLvQty = builder.proLvQty;
        this.cityLvQty = builder.cityLvQty;
        this.disLvQty = builder.disLvQty;
        this.unknownQty = builder.unknownQty;
        this.unknownIspQty = builder.unknownIspQty;
        this.orignQty = builder.orignQty;
        this.apiQty = builder.apiQty;
        this.ipipQty = builder.ipipQty;
    }

    public static class Builder {
        private Long totalQty = 0L;
        private Long chinaQty = 0L;
        private Long proLvQty = 0L;
        private Long cityLvQty = 0L;
        private Long disLvQty = 0L;
        private Long unknownQty = 0L;
        private Long unknownIspQty = 0L;
        private Long orignQty = 0L;
        private Long apiQty = 0L;
        private Long ipipQty = 0L;

        public Builder() {
        }

        public Builder totalQty(Long totalQty) {
            this.totalQty = totalQty;
            return this;
        }

        public Builder chinaQty(Long chinaQty) {
            this.chinaQty = chinaQty;
            return this;
        }

        public Builder proLvQty(Long proLvQty) {
            this.proLvQty = proLvQty;
            return this;
        }

        public Builder cityLvQty(Long cityLvQty) {
            this.cityLvQty = cityLvQty;
            return this;
        }

        public Builder disLvQty(Long disLvQty) {
            this.disLvQty = disLvQty;
            return this;
        }

        public Builder unknownQty(Long unknownQty) {
            this.unknownQty = unknownQty;
            return this;
        }

        public Builder unknownIspQty(Long unknownIspQty) {
            this.unknownIspQty = unknownIspQty;
            return this;
        }

        public Builder addTotalQty(Long totalQty) {
            this.totalQty += totalQty;
            return this;
        }

        public Builder addChinaQty(Long chinaQty) {
            this.chinaQty += chinaQty;
            return this;
        }

        public Builder addProLvQty(Long proLvQty) {
            this.proLvQty += proLvQty;
            return this;
        }

        public Builder addCityLvQty(Long cityLvQty) {
            this.cityLvQty += cityLvQty;
            return this;
        }

        public Builder addDisLvQty(Long disLvQty) {
            this.disLvQty += disLvQty;
            return this;
        }

        public Builder addUnknownQty(Long unknownQty) {
            this.unknownQty += unknownQty;
            return this;
        }

        public Builder addUnknownIspQty(Long unknownIspQty) {
            this.unknownIspQty += unknownIspQty;
            return this;
        }
        public Builder addOrignQty(Long orignQty) {
            this.orignQty += orignQty;
            return this;
        }

        public Builder addApiQty(Long apiQty) {
            this.apiQty += apiQty;
            return this;
        }
        public Builder addIpipQty(Long ipipQty) {
            this.ipipQty += ipipQty;
            return this;
        }

        public StaticIPDTO build() {
            return new StaticIPDTO(this);
        }
    }


    public Long getTotalQty() {
        return totalQty;
    }

    public void setTotalQty(Long totalQty) {
        this.totalQty = totalQty;
    }

    public Long getChinaQty() {
        return chinaQty;
    }

    public void setChinaQty(Long chinaQty) {
        this.chinaQty = chinaQty;
    }

    public Long getProLvQty() {
        return proLvQty;
    }

    public void setProLvQty(Long proLvQty) {
        this.proLvQty = proLvQty;
    }

    public Long getCityLvQty() {
        return cityLvQty;
    }

    public void setCityLvQty(Long cityLvQty) {
        this.cityLvQty = cityLvQty;
    }

    public Long getDisLvQty() {
        return disLvQty;
    }

    public void setDisLvQty(Long disLvQty) {
        this.disLvQty = disLvQty;
    }

    public Long getUnknownQty() {
        return unknownQty;
    }

    public void setUnknownQty(Long unknownQty) {
        this.unknownQty = unknownQty;
    }

    public Long getUnknownIspQty() {
        return unknownIspQty;
    }

    public void setUnknownIspQty(Long unknownIspQty) {
        this.unknownIspQty = unknownIspQty;
    }

    public Map<String, Integer> getIspDistribution() {
        return ispDistribution;
    }

    public void setIspDistribution(Map<String, Integer> ispDistribution) {
        this.ispDistribution = ispDistribution;
    }

    @Override
    public String toString() {
        return new StringBuffer().append("IP总量:").append(totalQty).append("\t中国数据总量:").append(chinaQty)
                .append("\t省级精度数量:").append(proLvQty).append("\t市级精度数量:").append(cityLvQty)
                .append("\t区级精度数量:").append(disLvQty).append("\t未知精度数量:").append(unknownQty)
                .append("\t未知运营商数量:").append(unknownIspQty)
                .append("\t原始数据量:").append(orignQty)
                .append("\t").toString();
    }

    public String ispDistribution() {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, Integer> entry : ispDistribution.entrySet()) {
            sb.append(entry.getKey()).append(":").append(entry.getValue()).append("\r\n");
        }
        return sb.toString();
    }
}
